package com.asianrapid.controller.sys;

import com.asianrapid.model.sys.CarEntity;
import com.asianrapid.model.sys.PageResult;
import com.asianrapid.service.sys.CarService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class CarController {

    private Logger log = LoggerFactory.getLogger(CarController.class);

    @Autowired
    private CarService carService;

    @GetMapping("/cars")
    public PageResult getAllCar(int pageSize, int page){

        PageResult pageResult = new PageResult();

//        pageResult.setData(carService.carList(id, page * pageSize, pageSize));
//        pageResult.setTotalCount(carService.carSize(id, page * pageSize, pageSize ));



        pageResult.setData(carService.carList( pageSize,page * pageSize ));
        pageResult.setTotalCount(carService.carSize( pageSize,page * pageSize ));
        log.debug("The method is ending");


//        pageResult.setData(userService.usersList(id, pageSize, page * pageSize));
//        pageResult.setTotalCount(userService.usersSize(id, pageSize, page * pageSize));
//        log.debug("The method is ending");

        return pageResult;

    }

    /*/menus/car*/
    @PostMapping("/menus/car")
    public void insertCar(@RequestBody CarEntity carEntity ){
        carService.insertCar(carEntity);
    }


    @PutMapping("/car/{id}")
    public CarEntity updateCar(@RequestBody CarEntity carEntity, @PathVariable int id) {
        if (carEntity.getId() == id) {
            carService.updateCar(carEntity);
        }
        log.debug("The method is ending");
        return carEntity;
    }

    /*delCars*/
    @DeleteMapping("/delCars")
    public List<String> deleteCar(@RequestBody List<String> groupId) {
        carService.deleteCar(groupId);
        return groupId;
    }

}
